<?php

namespace App\Strategys\Message;

use App\Services\ChatRoomService;

class CustomerMessage extends Message
{
    /**
     * 数据初始化
     * @param object $ws
     * @param int $fd
     */
    public function __construct(object $ws, int $fd)
    {
        parent::__construct($ws, $fd);
    }

    /**
     * 客服上线处理
     * @param int $user_id 客服编号
     */
    public function online(int $user_id = 0)
    {
        // 客服上线
        $service = new ChatRoomService();
        $customer_info = $service->customerOnline($user_id, $this->fd);
        if (empty($customer_info)) {
            $this->ws->push($this->fd, $this->failed(['message' => '当前账号不存在，或已被禁用~']));
        } else {
            $this->ws->push($this->fd, $this->success(['customer' => $customer_info]));
        }
        // TODO: Implement online() method.
    }

    /**
     * 发送消息
     * @param array $data
     * @return void
     */
    public function sendMessage(array $data)
    {
        $this->sendMessagePublic($data, 2);
        // TODO: Implement sendMessage() method.
    }

    /**
     * 下线操作
     * @param array $user_info
     */
    public function close(array $user_info)
    {
        // TODO: Implement close() method.
    }
}
